{% extends "base.html" %}
{% load static %}
{% block content %}
    <div class="row">
        <div class="col-lg">
            <div class="card">
                <div class="card-body">
                    <form method="post">{% csrf_token %}
                        <div class="form-group">
                            {% if form.non_field_errors %}
                                <ul class="errorlist non-field-errors">
                                    {% for error in form.non_field_errors %}
                                        <li>{{ error }}</li>
                                    {% endfor %}
                                </ul>
                            {% endif %}

                            {% for field in form %}
                                {% if field.errors %}
                                    <!-- 自定义错误样式 -->
                                    <div class="errorlist custom-error alert alert-warning alert-dismissible fade show" role="alert">
                                        {% for error in field.errors %}
                                            <li>{{ error }}</li>
                                        {% endfor %}
                                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                            <span aria-hidden="true">&times;</span>
                                        </button>
                                    </div>
                                {% endif %}



                                <div class="fieldWrapper form-group"> {% if field.field.required %}
                                    <span class="required text-danger">*</span> <!-- 表示该字段为必填 -->
                                {% endif %}
                                    {{ field.label_tag }} {{ field }}
                                </div>
                            {% endfor %}

                            {% for form in formset %}
                                {{ form.as_p }}  <!-- 或者逐个字段处理 -->
                                {% if form.non_field_errors %}
                                    <!-- 处理表单集中的非字段错误 -->
                                {% endif %}
                                {% for field in form.visible_fields %}
                                    {% if field.errors %}
                                        <!-- 与上面类似地处理表单集中的字段错误 -->
                                    {% endif %}
                                {% endfor %}
                            {% endfor %}

                            <input type="submit" value="提交" class="btn btn-primary">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
{% endblock %}